import { BROWSER_MODE, SET_BROWSER_MODE } from 'Constants/webConstants';

export default function changeBrowserMode(width, height) {
  return (dispatch, getState) => {
    const state = getState();
    let mode;
    let debug;
    if (width < height) {
      mode = BROWSER_MODE.VERTICAL;
      debug = '竖屏模式';
    } else if (width > 1920) {
      mode = BROWSER_MODE.HORIZONTAL_1920;
      debug = '横屏1920';
    } else {
      mode = BROWSER_MODE.HORIZONTAL_1366;
      debug = '横屏1366';
    }
    if (mode === state.webReducer.mode) {
      return;
    }
    console.log(`Browser Mode = ${debug}`);
    dispatch({
      type: SET_BROWSER_MODE,
      mode,
    });
  };
}
